﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using TRPOP.CMS.Message;
using TRPOP.CMS.Message.model;
using TRPOP.CMS.Message.UI;
using TRPOP.Common;
using TRPOP.CMS.Web.UI;

namespace TRPOP.CMS.Web.cms.Message
{
    public partial class messagereply : BaseAdmin
    {
        protected IMessage m_IMessage = MessageAccess.GetInstance();
        protected int intMessageId = 0;

        #region 页面事件
        protected void Page_Load(object sender, EventArgs e)
        {
            intMessageId = RequestHelper.RequestInt("id");

            if (!IsPostBack)
            {
                BindMessage();
                BindType();
                BindStatus();
                BindRepMessage();
            }
        }
        #endregion

        #region 页面方法
        //获取留言信息
        protected void BindMessage()
        {
            MessageInfo oInfo = null;
            if (intMessageId > 0)
            {
                oInfo = m_IMessage.GetMessageInfo(intMessageId);
            }
            if (oInfo != null)
            {
                MessageTitle.InnerHtml= oInfo.nvcMessageTitle;
                MessageContent.InnerHtml = oInfo.ntMessageContent;

                if (oInfo.iMessageSend <= 0)
                {
                    MesageSendID.InnerHtml = "";
                }
                else
                { 
                MesageSendID.InnerHtml = oInfo.iMessageSend.ToString();
                }
                
                MesageSendName.InnerHtml = oInfo.nvcMessageSend;
                ContactName.InnerHtml = oInfo.nvcContactName;
                Email.InnerHtml = oInfo.nvcContactEmail;
                Mobile.InnerHtml = oInfo.nvcContactMobile;
                Phone.InnerHtml = oInfo.nvcContactPhone;
                Zipcode.InnerHtml = oInfo.nvcContactPostCode;
                Address.InnerHtml = oInfo.nvcContactAddress;
                ddlType.SelectedValue = oInfo.iMessageTypeID.ToString();
                ddlStatus.SelectedValue = oInfo.iMessageStatusID.ToString();
                CreationTime.InnerHtml = oInfo.dtCreationTime.ToString();
            }
        }
        //绑定留言类型
        protected void BindType()
        {
            ddlType.DataSource = m_IMessage.GetMessageTypeInfoList(0, "", "");
            ddlType.DataTextField = "nvcMessageTypeName";
            ddlType.DataValueField = "iMessageTypeID";
            ddlType.DataBind();
        }

        //绑定留言状态
        protected void BindStatus()
        {
            ddlStatus.DataSource = m_IMessage.GetMessageStatusList(0, "", "");
            ddlStatus.DataTextField = "nvcMessageStatusName";
            ddlStatus.DataValueField = "iMessageStatusID";
            ddlStatus.DataBind();
        }

        //绑定回复留言
        protected void BindRepMessage()
        {
            List<MessageReplyInfo> olist = null; 

            string strcondition="";
            string strOrderBy=string.Empty;
            int intOutcount=0;

            if (intMessageId > 0)
            {
                strcondition += " AND iMessageID=" + intMessageId;
                olist = m_IMessage.GetMessageReplyInfoListByPager(1, 1, strcondition, strOrderBy, out intOutcount);
            }
            if (olist.Count>0)
            {
                divReply.Visible = true;
                ReplyName.InnerHtml = olist[0].nvcMessageReplyUserName;
                ReplyTitle.InnerHtml = olist[0].nvcMessageReplyTitle;
                ReplyContent.InnerHtml = olist[0].ntMessageReplyContent;
                ReplyTime.InnerHtml = olist[0].dtMessageReplyTime.ToString();
                if (olist[0].iDisplayOrder <= 0)
                {
                    ReplyOrder.InnerHtml = "";
                }
                else
                {
                    ReplyOrder.InnerHtml = olist[0].iDisplayOrder.ToString();
                }
            }
        }
        #endregion
    }
}